package org.test;

import java.lang.reflect.Method;

interface Messages {
	public String getText();
}

class TextMessage implements Messages {
	public String getText() {
		return "TextMessage";
	}
}

class ObjectMessage implements Messages {
	public String getText() {
		return "ObjectMessage";
	}
}

public class Message {

	public static void main(String[] args) {
		System.out.println(-12%-5);
//		Message message = new Message();
//		message.getText(new TextMessage());
	}

	public void getText(Messages message) {
		Class clazz = message.getClass();
		String name = message.getClass().getName();
		try {
			// Messages obj = Class.forName(name);
			// System.out.println(obj.getClass());
			Method method = message.getClass().getMethod("getText");
			String text = (String) method.invoke(message, null);
			System.out.println(text);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
